package test.LIfeService;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class PersonalActivity extends JFrame {

    public PersonalActivity() {
        // 设置窗口标题
        setTitle("亲子活动");
        // 设置窗口大小
        setSize(600, 400);
        // 设置默认关闭操作
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // 点击"叉"关闭当前窗口
        // 将窗口居中显示
        setLocationRelativeTo(null);

        // 创建主面板
        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new BorderLayout());

        // 创建顶部面板用于放置按钮
        JPanel topPanel = new JPanel();
        topPanel.setLayout(new GridLayout(1, 3)); // 使用 GridLayout 均匀分布按钮

        // 创建三个按钮并添加到顶部面板
        JButton upcomingEventsButton = new JButton("近日要举行的活动");
        JButton earlyEducationButton = new JButton("早教课程");
        JButton interestClassesButton = new JButton("兴趣班");

        // 设置按钮字体为支持中文的字体
        Font buttonFont = new Font("SimSun", Font.BOLD, 16);
        upcomingEventsButton.setFont(buttonFont);
        earlyEducationButton.setFont(buttonFont);
        interestClassesButton.setFont(buttonFont);

        // 为"近日要举行的活动"按钮添加 ActionListener
        upcomingEventsButton.addActionListener(e -> {
            JOptionPane.showMessageDialog(this, "为共建绿色家园，XX社区将于6月25日（周日）9:00-11:30在社区公园开展“清洁环境，美化家园”志愿活动。");
        });

        // 为"早教课程"按钮添加 ActionListener
        earlyEducationButton.addActionListener(e -> {
            JOptionPane.showMessageDialog(this, "为促进0-3岁宝宝全面发展，XX早教中心推出“快乐启蒙”亲子课程，每周六上午9:30-11:00开课。");
        });

        // 为"兴趣班"按钮添加 ActionListener
        interestClassesButton.addActionListener(e -> {
            JOptionPane.showMessageDialog(this, "为激发孩子艺术潜能，XX艺术中心现开设周末少儿美术班（5-12岁），课程涵盖水彩、黏土、创意手工等，");
        });

        topPanel.add(upcomingEventsButton);
        topPanel.add(earlyEducationButton);
        topPanel.add(interestClassesButton);

        // 将顶部面板添加到主面板的顶部
        mainPanel.add(topPanel, BorderLayout.NORTH);

        // 修改: 确保点击"叉"按钮后返回到 LIFeService 界面
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent windowEvent) {
                LIFeService lifeService = new LIFeService(); // 创建 LIFeService 实例
                lifeService.setVisible(true); // 显示 LIFeService 界面
            }
        });
        // 将主面板和底部面板添加到窗口
        add(mainPanel, BorderLayout.CENTER);

    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            PersonalActivity personalActivity = new PersonalActivity();
            personalActivity.setVisible(true);
        });
    }
}